package cn.bdqn.controller;

import cn.bdqn.bean.result.Result;
import cn.bdqn.bean.result.ResultCode;
import cn.bdqn.bean.result.ResultGenerator;
import cn.bdqn.domain.Room;
import cn.bdqn.service.RoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/HM/room")
public class RoomController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private RoomService roomService;

    @GetMapping("/getRoomList/{floorId}")
    public Result<Map<String, Object>> getRoomList(@PathVariable("floorId") Integer floorId) {

        Map<String, Object> data = new HashMap<>();
        logger.info("进入了 getRoomList(获取病房列表) 方法");
        try {
            List<Room> rooms = roomService.queryByFloorId(floorId);
            data.put("rooms", rooms);
        } catch (Exception e) {
            logger.error("getRoomList(获取病房列表)方法抛出异常:" + e.getMessage());
            e.printStackTrace();
            return ResultGenerator.genFailResult("网络异常", ResultCode.INTERNAL_SERVER_ERROR);
        }
        return ResultGenerator.genSuccessResult(data);
    }
}
